package com.leyou.listeners;

import com.leyou.search.service.IndexService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: YHL
 * @time: 2021/3/3 20:21
 */
@Component
public class GoodsListeners {

    @Autowired
    private IndexService indexService;
// 消费者，通过监听器获取消息，监听队列 队列要完成和交换机的绑定
    @RabbitListener(bindings =@QueueBinding(
            exchange = @Exchange(name = "yhl", type = ExchangeTypes.TOPIC),
            value = @Queue(name = "item.up.queue",durable = "true"),
            key = "item.up"
    ))
    public void handleGoodsUp(Long id){

        this.indexService.handleGoodsUp(id);
    }
    // 消费者，通过监听器获取消息，监听队列 队列要完成和交换机的绑定
    @RabbitListener(bindings =@QueueBinding(
            exchange = @Exchange(name = "yhl", type = ExchangeTypes.TOPIC),
            value = @Queue(name = "item.down.queue",durable = "true"),
            key = "item.down"
    ))
    public void handleGoodsDown(Long id){
        this.indexService.handleGoodsDown(id);
    }
}
